<template>
  <el-dialog
    :title="title"
    :visible.sync="openSheet"
    width="70%"
    :destroy-on-close="true"
    :close-on-click-modal="false"
  >
    <!-- 项目计划信息 开始-->
    <projectplanbase-info :project-plan-base-information="projectPlanBaseInformation" />
    <!-- 项目计划信息 结束-->
    <!-- 项目计划基础信息 开始-->
    <projectplaninfo-info :project-plan-info-information="projectPlanInfoInformation" />
    <!-- 项目计划基础信息 结束-->
    <!-- 项目计划法律信息 开始-->
    <projectplanlaw-info :project-plan-law-information="projectPlanLawInformation" />
    <!-- 项目计划法律信息 结束-->
    <!-- 项目计划客户信息 开始-->
    <projectplancustomer-info :project-plan-customer-information="projectPlanCustomerInformation" />
    <!-- 项目计划客户信息 结束-->
    <div slot="footer" class="dialog-footer">
      <el-button @click="cancel">{{ $t('cancel') }}</el-button>
    </div>
  </el-dialog>
</template>

<script>
import projectplanbaseInfo from '../../projectplanbase/components/projectplanbase-info.vue';
import ProjectplaninfoInfo from '../../projectplaninfo/components/projectplaninfo-info.vue';
import ProjectplanlawInfo from '../../projectplanlaw/components/projectplanlaw-info.vue';
import ProjectplancustomerInfo from '../../projectplancustomer/components/projectplancustomer-info.vue';
import { getProjectPlanInfoListApi } from '@/views/projectbase/projectplaninfo/api/projectplaninfo.api';
import { getProjectPlanLawListApi } from '@/views/projectbase/projectplanlaw/api/projectplanlaw.api';
import { getProjectPlanCustomerListApi } from '@/views/projectbase/projectplancustomer/api/projectplancustomer.api';

export default {
  components: { projectplanbaseInfo, ProjectplaninfoInfo, ProjectplanlawInfo, ProjectplancustomerInfo },
  data() {
    return {
      projectPlanBaseInformation: {},
      projectPlanInfoInformation: {},
      projectPlanLawInformation: {},
      projectPlanCustomerInformation: {},
      title: undefined,
      openSheet: false,
      queryparams: {
        projectPlanFK: undefined
      },
      infolist: [],
      lawlist: [],
      customList: [],
      projectPlanId: undefined
    };
  },
  computed: {
    labelWidth() {
      return this.$i18n.locale === 'en' ? '150px' : '80px';
    }
  },
  methods: {
    async openSheetDialog(data) {
      this.openSheet = !this.openSheet;
      this.title = this.$t('projectPlanBaseInquireTitle');
      this.projectPlanBaseInformation = data;
      this.projectPlanId = data.id
      this.getProjectPlanInfoList()
      this.getProjectPlanLawList()
      this.getProjectPlancustomList()
    },
    cancel() {
      this.openSheet = !this.openSheet;
    },
    // 获取项目计划基础信息表
    async getProjectPlanInfoList() {
      this.loading = true
      this.queryparams.projectPlanFK = this.projectPlanId
      var resp = await getProjectPlanInfoListApi({ ...this.queryparams })
      if (resp.success && resp.data.results.length > 0) {
        this.infolist = resp.data.results[0] // 一个项目计划只能对应一条基础信息
        this.projectPlanInfoInformation = { ...this.infolist } // 将获取的数据赋值给form
      } else {
        this.infolist = []
      }
      this.loading = false
    },
    async getProjectPlanLawList() {
      this.loading = true
      this.queryparams.projectPlanFK = this.projectPlanId
      var resp = await getProjectPlanLawListApi({ ...this.queryparams })
      if (resp.success && resp.data.results.length > 0) {
        this.lawlist = resp.data.results[0] // 一个项目计划只能对应一条法律信息
        this.projectPlanLawInformation = { ...this.lawlist } // 将获取的数据赋值给form
      } else {
        this.lawlist = []
      }
      this.loading = false
    },
    async getProjectPlancustomList() {
      this.loading = true
      this.queryparams.projectPlanFK = this.projectPlanId
      var resp = await getProjectPlanCustomerListApi({ ...this.queryparams })
      if (resp.success && resp.data.results.length > 0) {
        this.customList = resp.data.results[0] // 一个项目计划只能对应一条基础信息
        this.projectPlanCustomerInformation = { ...this.customList } // 将获取的数据赋值给form
      } else {
        this.customList = []
      }
      this.loading = false
    }
  }
};
</script>

<style scoped>
@import "~@/views/projectbase/projectcss/project.css";
</style>
